package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.entity.VisitHistory;
import com.example.vo.VisitHistoryVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface VisitHistoryMapper extends BaseMapper<VisitHistory> {
    //无关联 @Select("select id,user_id,openid,video_id,course_id,video_location,delete_flag from visit_history order by create_date DESC limit #{n}")
    @Select("select vh.id,u.nick_name,vh.openid,v.video_title,c.course_name,vh.video_location from tb_visit_history vh join tb_user u on vh.user_id=u.id join tb_course c on vh.course_id=c.id join tb_video v on vh.video_id=v.id order by vh.create_date DESC limit #{n}")//有关联
    List<VisitHistoryVO>  selectByLimit(int number);

    @Update("update tb_visit_history set delete_flag = 0 where id= #{n}")
    Integer  falseDelete(int id);

    @Select("select video_location  from tb_visit_history where tb_visit_history.user_id = #{n}")
    List<VisitHistory> findVideoLocation(int id);

    @Delete("update tb_visit_history SET delete_flag = REPLACE(delete_flag , '1', '0' ) ")
    Integer deleteAll();
}
